﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace HRLib
{
    public class Employee : TaxEntity
    {
        public const float FICA_TAX_RATE = .0765f;

        #region fields
        private float salary;
        private float ytdSalary;
        private float ytdTax;
        #endregion

        #region constructors
        protected Employee()
        {
        }

        public Employee(string name, string ssn) 
            : this(name, ssn, 100)
        {
        }

        public Employee(string name, string ssn, float salary)
            : base(name, ssn)
        {
            this.salary = salary;
            ytdSalary = 0;
            ytdTax = 0;
        }
        #endregion

        #region properties
        public override string TaxIdRegex
        {
            get { return @"^\d\d\d-\d\d-\d{4}$"; }
        }


        public float Salary
        {
            get { return salary; }
            set
            {
                if (value > 20 && value < 1000)
                    salary = value;
                else
                    throw new ArgumentException(" 20  < Salary < 1000");
            }
        }

        public float YtdSalary
        {
            get { return ytdSalary; }
        }
        public float YtdTax
        {
            get { return ytdTax; }
        }
        #endregion

        /// <summary>
        /// Calculates this employee's net pay based on Salary
        /// </summary>
        /// <returns>The net pay (gross - taxes)</returns>
        public override float Pay()
        {
            float tax = Salary * FICA_TAX_RATE;
            ytdTax += tax;
            ytdSalary += Salary;
            return Salary - tax;
        }

    }
}
